package com.hanhai.zrb.backend.admin.dao.mybatis;

import java.util.List;
import java.util.Map;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import com.hanhai.zrb.api.biz.dao.mybatis.base.BaseMapper;
import com.hanhai.zrb.backend.admin.model.Privilege;

public interface PrivilegeDao extends BaseMapper {

	@Select("select * from privilege where acl=#{acl}")
	Map<String, Object> get(Integer acl);

	@Select("select * from privilege where pacl=#{acl}")
	List<Map<String, Object>> listChild(Integer acl);

	@Select("select * from privilege order by sort desc")
	List<Map<String, Object>> listPage();

	@Select("select * from privilege")
	List<Map<String, Object>> listAll();

	@Select("select * from privilege where ismenu=1 order by level asc,sort asc,acl desc")
	List<Privilege> listAllMenu();

	//@Select("select p.enname,p.name,p.acl,p.url from  back_user_role ur,"
	//		+ "role_privilege rp,privilege p "
	//		+ "where ur.role_id = rp.role_id and rp.acl = p.acl and ur.user_id = #{userId} order by level asc,sort asc,acl desc")
	List<Privilege> listAllPrivilege(@Param("userId")Long userId,@Param("ismenu")boolean ismenu);
	
	//@Select("select * from privilege")
//	List<Privilege> findAllByUserId(Long userId);

	@Deprecated
	List<Map<String, Object>> findAllByUserId2(Long userId);

	@Insert("insert into privilege(pacl,name,enname,sort,url,ismenu,level) values (#{pacl},#{name},#{enname},#{sort},#{url},#{ismenu},#{level})")
	void add(Privilege privilege);

	@Update("update privilege set pacl=#{pacl},name=#{name},enname=#{enname},sort=#{sort},url=#{url},ismenu=#{ismenu},level=#{level} where acl=#{acl}")
	void update(Privilege privilege);

	// 物理删除
	@Delete("delete from privilege where acl=#{acl} or pacl = #{acl}")
	void delete(Integer acl);

}
